import Vue from 'vue';
import Vuex from 'vuex';
import axios from 'axios';
Vue.use(Vuex);

var store = new Vuex.Store({
    state: {
        goodsmenu:[]
    },
    getters: {

    },
    mutations: {
        setgoodsmsg: function (state, value) {
            state.goodsmsg = value;
        },
        setmenu:function(state,value){
            // console.log(value);
            state.goodsmenu = value;
            // console.log(this.state.goodsmenu.length)
        }
    },
    actions: {
        requestJion: function (context, data) {
            return new Promise(function (resolve, reject) {
                axios.post("/api/goods/add", data).then(res => {
                    resolve(res);
                })
            })
        },
        loginRequest:function(context,data){
            return new Promise(function (resolve, reject) {
                 axios.post("/api/islogin", data).then(res => {
                     resolve(res.data.isLogin.isLogin)
                })
            })
        },
        goodsSearch:function(context,data){
            return new Promise(function(resolve,reject){
                axios.post("/api/search",data).then(res=>{
                    
                //   console.log(res.data.data)
                    context.commit("setmenu",res.data.data);
                    
                })
            })
        }

    }
})

export default store;
